<?php


class Solution
{
    public function firstUniqueChar($strings)
    {
        $strLen  = strlen($strings);
        if($strLen <1) {
            return -1;
        }

        if($strLen == 1) {
            return 0;
        }
        $i=0;
        $strArr = [];
        $index = -1;
        while ($i < $strLen) {
            $key = $strings{$i};
            if(array_key_exists($key,$strArr)) {
                $strArr[$key] = ++$strArr[$key];
            } else {
                $strArr[$key] = 1;
            }
            $i++;
        }

        foreach ($strArr as $key=>$value) {
            if($value == 1) {
                $index = $key;
                break;
            }
        }

        $k=0;
        while ($k < $strLen) {
            $key = $strings{$k};
            if($key == $index) {
                return $k;
            }
            $k++;
        }
        return -1;

    }
}

$strings = "aabb";
$res = (new Solution())->firstUniqueChar($strings);
var_dump($res);